import React from 'react';
import { ts2Formatter,renderState,renderEnable } from 'utils';
import { actions } from 'mirrorx';
{/*
可配置化种类：

1、表格头部字段 
    1、列表页表格头部字段集合 mainTableColumn
    2、编辑页表格头部字段集合 childTableColumn

2、编辑框的字段
    1、编辑页 直接显示在页面的编辑字段 FormField
    2、编辑页 需要点击表格的增行弹框编辑的字段 FormTableField
    3. 列表页查询区域  searchField

3.表头部的按钮  headerButtonSets

4.表行尾部按钮  columnButtonSets
*/}

//表头信息

//字段属性

//基本信息
const FormDataHeader = [
    {
        enname: "billCode",
        zhname: "单据号",
        edit: true,
        hidepage:{0:true,3:true},
        type: "FormControl",
    },
    {
        enname: "organizationId",
        codename: "organizationCode",
        showname: "organizationName",
        zhname: "隶属组织",
        type: "RefComponent",
        edit:true,
        refname:"organization",
        required: true,
        cascadeName: [{
            paramkey: "EQ_customerAreas.organization.id",
            childtype: "DataHeader",
            refKey: "refpk",
            dtoKey: "organizationId",
            offers: "customerId",
            resetOffersFlag: true,
        },{
            paramkey: "EQ_organization.id",
            childtype: "DataHeader",
            refKey: "refpk",
            dtoKey: "organizationId",
            offers: "sliceAreaId",
            resetOffersFlag: true,
        },{
            paramkey: "EQ_organization",
            childtype: "DataHeader",
            refKey: "refpk",
            dtoKey: "organizationId",
            offers: "activityPlanTemplateId",
            resetOffersFlag: true,
        }
        ]
    },
    {
        enname: "activityPlanTemplateId",
        codename: "activityPlanTemplateCode",
        showname: "activityPlanTemplateName",
        zhname: "活动策划模板",
        edit: true,
        alias:"organizationId",
        param:{
            "EQ_enableState":"0",
        },
        type: "RefComponent",
        refname:"activityTemplateRef",
        required: true,
    },
    {
        enname: "sliceAreaId",
        codename: "sliceAreaCode",
        showname: "sliceAreaName",
        zhname: "部门片区",
        edit: false,
        alias:"organizationId",
        type: "RefComponent",
        refname:"departmentRef",
        required: false,
        hidepage: { 0:true,3:true },
    },
    {
        enname: "activityTitle",
        zhname: "活动标题",
        type: "FormControl",
        required: true,
        pattern: /^\S*$/,
        message: "不能有空格",
        edit: true,
    },
    {
        enname: "brandId",
        codename: "brandCode",
        showname: "brandName",
        zhname: "商品品牌",
        edit: true,
        required:true,
        type: "RefComponent",
        refname: "brandref",
    },
    {
        enname: "goodsCategoryId",
        codename: "goodsCategoryCode",
        showname: "goodsCategoryName",
        zhname: "商品品类",
        edit: true,
        required:true,
        type: "RefComponent",
        refname: "terminalGoodsCate",
    },

    {
        enname: "saleStatisticBasisId",
        codename: "saleStatisticBasisCode",
        showname: "saleStatisticBasisName",
        zhname: "销量统计依据",
        code: "SALE_STATISTIC_BASIS",
        type: "Select",
        edit: true,
        required: true,
    },
    {
        enname:"activityStartDate",
        zhname:"活动开始日期",
        type: "DatePicker",
        format:"YYYY-MM-DD",
        edit: true,
        required: true,
    },
    {
        enname: "activityEndDate",
        zhname: "活动截止日期",
        type: "DatePicker",
        disabledDate:"activityStartDate",
        format:"YYYY-MM-DD",
        edit:true,
        required: true,
    },
    {
        enname: "planSaleNumTotal",
        zhname: "预计台量合计",
        edit: false,
        type: "InputNumber",
    },
    {
        enname: "discountAmountTotal",
        zhname: "折让合计",
        edit: false,
        type: "InputNumber",
    },
    {
        enname: "wireTransferAmountTotal",
        zhname: "电汇合计",
        edit: false,
        type: "InputNumber",
    },
    {
        enname: "purchaseGiftAmountTotal",
        zhname: "采购合计",
        edit: false,
        type: "InputNumber",
    },
    {
        enname: "salaryAmountTotal",
        zhname: "薪资合计",
        edit: false,
        type: "InputNumber",
    },
    {
        enname: "planCostAmountTotal",
        zhname: "计划费用额合计",
        edit: false,
        type: "InputNumber",
    },
    {
        codename: "state",
        zhname: "审批状态",
        hidepage:{0:true,3:true},
        edit: false,
        code:"BILL_STATUS",
        type: "Select",
        required: false,
    },
    {
        enname:"approveTime",
        zhname:"审核日期",
        required: false,
        hidepage:{0:true,1:false,2:false,3:true},
        type: "DatePicker",
        format:"YYYY-MM-DD",
        edit: false
    },
    {
        enname: "ext01",
        zhname: "创建人",
        type: "FormControl",
        required: false,
        hidepage: { 0:true,3:true},
        edit: false,
    },
    {
        enname: "creationTime",
        zhname: "创建日期",
        type: "DatePicker",
        required: false,
        format: "YYYY-MM-DD",
        hidepage: { 0:true,3:true},
        edit: false,
    },
    {
        enname: "ext02",
        zhname: "编辑人",
        type: "FormControl",
        required: false,
        hidepage: { 0:true,3:true},
        edit: false,
    },
    {
        enname: "modifiedTime",
        zhname: "编辑日期",
        type: "DatePicker",
        format: "YYYY-MM-DD",
        required: false,
        hidepage: { 0:true,3:true},
        edit: false,
    },
];

const columnactivityDesignDetails = [
    {
        title: "行号",
        dataIndex: "ext01",
        fixed: "left",
        detailwidth: 30,
        key:"ext01",
    },
    {
        title: "商品型号",
        dataIndex: "goodsModelName",
        key: "goodsModelId",
        renderType: "refcomponent",
        detailwidth: 125,
        validate: false,
        fixed: "left",
        filedProps: {
            title: "商品",
            refName: "goodsRef",
            fieldName: "goodsName",
            reffields: { refpk: "goodsModelId", refname: "goodsModelName", refcode: "goodsModelCode" }
        },
    },
    {
        title: "套购商品",
        dataIndex: "goodsSeriesName",
        key: "goodsSeriesId",
        renderType: "refcomponent",
        detailwidth: 125,
        validate: false,
        fixed: "left",
        filedProps: {
            title: "商品",
            refName: "productCombinationRef",
            fieldName: "goodsName",
            aliasparam: [{
                paramkey: "EQ_organization",
                alias: "organizationId",
            }],
            reffields: { refpk: "goodsSeriesId", refname: "goodsSeriesName", refcode: "goodsSeriesCode" }
        },
    },
    {
        title: "预计台量",
        dataIndex: "planSaleNum",
        key: "planSaleNum",
        width: 75,
        edit: true,
        renderType: "inputnumber",
        required: true,
        fixed: "left",
        filedProps: {
            min: 0,
        }
    },
    {
        title: "供价",
        dataIndex: "unitPrice",
        key: "unitPrice",
        width: 100,
        edit: true,
        renderType: "inputnumber",
        required: true,
        fixed: "left",
        filedProps: {
            except:0,
            min: 0,
        }
    },
    {
        dataIndex: "marketResource",
        key: "marketResource",
        title: "市场资源(元/台)",
        width: 125,
        edit: true,
        filedProps: {
            except:0,
            min: 0,
        }
    },
    {
        dataIndex: "discountSingle",
        key: "discountSingle",
        title: "折让-单台(元/台)",
        width: 125,
        edit: true,
        hidepage: { 0: true, 1: true, 2: true },
        renderType: "inputnumber",
        filedProps: {
            min: 0,
        }
    },
    {
        dataIndex: "discountSingleAppend",
        key: "discountSingleAppend",
        title: "折让-开单提成(元/台)",
        width: 125,
        edit: true,
        hidepage: { 0: true, 1: true, 2: true },
        renderType: "inputnumber",
        filedProps: {
            min: 0,
        }
    },
    {
        dataIndex: "discountSaleCost",
        key: "discountSaleCost",
        title: "折让-销售费用%",
        width: 125,
        edit: true,
        hidepage: { 0: true, 1: true, 2: true },
        renderType: "inputnumber",
        filedProps: {
            min: 0,
            max:100
        }
    },
    {
        dataIndex: "discountReserveCost",
        key: "discountReserveCost",
        title: "折让-预留费用%",
        width: 125,
        edit: true,
        hidepage: { 0: true, 1: true, 2: true },
        renderType: "inputnumber",
        filedProps: {
            min: 0,
            max:100
        }
    },
    {
        dataIndex: "discountTotal",
        key: "discountTotal",
        title: "折让-小计(元)",
        edit: true,
        hidepage: { 0: true, 1: true, 2: true },
        width: 125,
        filedProps: {
            min: 0,
        }
    },
    {
        dataIndex: "salaryWithOrder",
        key: "salaryWithOrder",
        title: "薪资-带单(元/台)",
        width: 125,
        edit: true,
        hidepage: { 0: true, 1: true, 2: true },
        renderType: "inputnumber",
        filedProps: {
            min: 0,
        }
    },
    {
        dataIndex: "salaryTransferCommission",
        key: "salaryTransferCommission",
        title: "薪资-变动提成(元/台)",
        width: 125,
        edit: true,
        hidepage: { 0: true, 1: true, 2: true },
        renderType: "inputnumber",
        filedProps: {
            min: 0,
        }
    },
    {
        dataIndex: "salarySaleInspire",
        key: "salarySaleInspire",
        title: "薪资-销售激励%",
        width: 125,
        edit: true,
        hidepage: { 0: true, 1: true, 2: true },
        renderType: "inputnumber",
        filedProps: {
            min: 0,
            max:100
        }
    },
    {
        dataIndex: "salaryTotal",
        key: "salaryTotal",
        title: "薪资-小计(元)",
        edit: true,
        hidepage: { 0: true, 1: true, 2: true },
        width: 125,
        filedProps: {
            min: 0,
        }
    },
    {
        dataIndex: "purchaseGift",
        key: "purchaseGift",
        title: "采购-赠品费用(元/台)",
        width: 125,
        edit: true,
        hidepage: { 0: true, 1: true, 2: true },
        renderType: "inputnumber",
        filedProps: {
            min: 0,
        }
    },
    {
        dataIndex: "purchaseGiftPercent",
        key: "purchaseGiftPercent",
        title: "采购-赠品费率(%)",
        width: 125,
        edit: true,
        hidepage: { 0: true, 1: true, 2: true },
        renderType: "inputnumber",
        filedProps: {
            min: 0,
            max:100
        }
    },
    {
        dataIndex: "purchaseGiftTotal",
        key: "purchaseGiftTotal",
        title: "采购-赠品小计(元)",
        edit: true,
        hidepage: { 0: true, 1: true, 2: true },
        width: 125,
        filedProps: {
            min: 0,
        }
    },
    {
        dataIndex: "wireSingleInspire",
        key: "wireSingleInspire",
        title: "电汇-单台激励(元/台)",
        width: 125,
        edit: true,
        hidepage: { 0: true, 1: true, 2: true },
        renderType: "inputnumber",
        filedProps: {
            min: 0,
        }
    },
    {
        dataIndex: "wireSaleInspire",
        key: "wireSaleInspire",
        title: "电汇-销售激励%",
        width: 125,
        edit: true,
        hidepage: { 0: true, 1: true, 2: true },
        renderType: "inputnumber",
        filedProps: {
            min: 0,
            max:100
        }
    },
    {
        dataIndex: "wireTransfer",
        key: "wireTransfer",
        title: "电汇-小计(元)",
        edit: true,
        hidepage: { 0: true, 1: true, 2: true },
        width: 125,
        filedProps: {
            min: 0,
        }
    },
    {
        dataIndex: "planCostAmountTotal",
        key: "planCostAmountTotal",
        title: "计划费用额合计(元)",
        edit: true,
        width: 125,
        filedProps: {
            min: 0,
        }
    },
    {
        title: "备注",
        dataIndex: "remark",
        renderType: "input",
        pattern:/^\S*$/,
        patternMessage: "不能有空格",
        width:100,
        filedProps: {
            defaultValue: "",
            maxLenght: '200',
        },
        validate:false,
        key: "remark",
    },
]

const columnactivityDesignConnects = [
    {
        title: "下游单据名称",
        dataIndex: "downStreamName",
        key: "downStreamName",
        detailwidth: 100,
    },
    {
        title: "下游单据号",
        dataIndex: "downStreamBillCode",
        key: "downStreamBillCode",
        detailwidth: 150,
        render:(text,record) => {
            if (record.downStreamName==="活动方案单") {
                return <a 
                value="ActivityPlan" 
                name="活动方案单"
                onClick = {(e)=>{
                    e.preventDefault();//阻止默认事件
                    window.top.handleClick(e,1);//调用打开新页签方法
                }}
                href={encodeURIComponent(encodeURIComponent(`/fmcg-web-react/OrderFish#/ActivityPlan-edit?search_id=${record.ext02}&btnPageFlag=${2}`))} >
                {text}
            </a> 
            }
        }
    },
    {
        title: "单据日期",
        dataIndex: "ext03",
        key: "ext03",
        detailwidth: 100,
        render: (text, record, index) => {
            return text && ts2Formatter(text,1);
        }
    },
    {
        title: "部门片区",
        dataIndex: "ext05",
        key: "ext05",
        detailwidth: 100,
    },
    {
        title: "单据状态",
        dataIndex: "ext06",
        key: "ext06",
        detailwidth: 100,
        render: (text, record, index) => {
            if (text=="0") {
                return "自由";
            }else if (text=="1") {
                return "提交";
            }else if (text=="2") {
                return "审核中";
            }else if (text=="3") {
                return "审核通过";
            }
        }
    },
    {
        title: "活动开始日期",
        dataIndex: "ext07",
        key: "ext07",
        detailwidth: 100,
        render: (text, record, index) => {
            return text && ts2Formatter(text,1);
        }
    },
    {
        title: "活动结束日期",
        dataIndex: "ext08",
        key: "ext08",
        detailwidth: 100,
        render: (text, record, index) => {
            return text && ts2Formatter(text,1);
        }
    },
    {
        title: "预计台量合计",
        dataIndex: "ext09",
        key: "ext09",
        detailwidth: 100,
    },
    {
        title: "计划费用额合计",
        dataIndex: "ext10",
        key: "ext10",
        detailwidth: 100,
    },
    {
        title: "计划销售额合计",
        dataIndex: "ext11",
        key: "ext11",
        detailwidth: 100,
    },
    {
        title: "计划报销额合计",
        dataIndex: "ext12",
        key: "ext12",
        detailwidth: 100,
    },
    {
        title: "费用率",
        dataIndex: "ext13",
        key: "ext13",
        detailwidth: 100,
    },
    {
        title: "制单人",
        dataIndex: "ext04",
        key: "ext04",
        detailwidth: 100,
    },
]

const columnactivityDesignAttachments = [
    {
        title: "标题",
        dataIndex: "filename",
        key: "filename",
        detailwidth: 250,
    }, {
        title: "上传时间",
        dataIndex: "creationTime",
        key: "creationTime",
        detailwidth: 150,
        render: (text, record, index) => {
            return text && ts2Formatter(text,1);
        }
    },
    {
        title: "缩略图",
        dataIndex: "fileUrl",
        key: "fileUrl",
        width: 150,
        render: (text, record, index) => {
            if(record.fileUrl.search("jpg") != -1 || record.fileUrl.search("jpeg") != -1 ||record.fileUrl.search("png") != -1){
                return <span>
                <img style={{"width":"35px"}} src={text} />
             </span>
            }else {
                return ""
            }
        }
    }, 
    {
        title: "创建人",
        dataIndex: "creatorname",
        key: "creatorname",
        width: 150,
    }
]

//表单字段
export const FormField = {
    "DataHeader": {
        "title": "基础信息",
        "Field": FormDataHeader
    },
}

//表格弹框表单字段
export const FormTableField = {
}

//渲染成字表表格的头
export const childTableColumn = {
    "activityDesignDetails": {
        "title": "活动策划明细",
        "type": "grid",
        "column": columnactivityDesignDetails
    },
    "activityDesignConnects": {
        "title": "活动策划关联",
        "type": "grid",
        "column": columnactivityDesignConnects
    },
    "activityDesignAttachments": {
        "title": "附件",
        "type": "grid",
        "column": columnactivityDesignAttachments
    },
}

//渲染成字表表格的头
export const mainTableColumn = [
    {
        title: "单据号",
        dataIndex: "billCode",
        width: 150,
        key: "billCode",
        render: (text, record) => {
            return <a style={{ "cursor": "pointer" }}
                onClick={() => {
                    actions.routing.push(
                        {
                            pathname: 'ActivityDesign-edit',
                            search: `?search_id=${record.id}&btnPageFlag=2`,
                        }
                    );
                    // location.reload();
                }}
            >
                {text}
            </a >;
        }
    },
    {
        title: "所属组织",
        dataIndex: "organizationName",
        key: "organizationName",
    },
    {
        title: "活动标题",
        dataIndex: "activityTitle",
        key: "activityTitle",
    },
    {
        title: "活动开始时间",
        dataIndex: "activityStartDate",
        key: "activityStartDate",
        width: 120,
        render: (text) => {
            return text && ts2Formatter(text)
        }
    },
    {
        title: "活动结束时间",
        dataIndex: "activityEndDate",
        key: "activityEndDate",
        width: 120,
        render: (text) => {
            return text && ts2Formatter(text)
        }
    },
    {
        title: "部门片区",
        width: 120,
        dataIndex: "sliceAreaName",
        key: "sliceAreaName",
    },
    {
        title: "品牌",
        width: 120,
        dataIndex: "brandName",
        key: "brandName",
    },
    {
        title: "品类",
        width: 120,
        dataIndex: "goodsCategoryName",
        key: "goodsCategoryName",
    },
    {
        title: "审批状态",
        dataIndex: "state",
        key: "state",
        width: 70,
        render:(text, record, index)=> {
            return renderState(text);
        },
    },
    {
        title:"审核日期",
        dataIndex:"approveTime",
        key: "approveTime",
        width: 90,
        render:(text) => {
            return text && ts2Formatter(text);
        },
    },
    {
        title: "创建人",
        width: 120,
        dataIndex: "ext01",
        key: "ext01",
    },
    {
        title: "创建日期",
        dataIndex: "creationTime",
        key: "creationTime",
        width: 120,
        render: (text) => {
            return text && ts2Formatter(text)
        }
    },
    {
        title: "修改人",
        width: 120,
        dataIndex: "ext02",
        key: "ext02",
    },
    {
        title: "修改日期",
        dataIndex: "modifiedTime",
        key: "modifiedTime",
        width: 120,
        render: (text) => {
            return text && ts2Formatter(text)
        }
    },
]

export const searchField = [
    {
        enname: "creationTime",
        zhname: "制单日期",
        required: false,
        type: "RangePicker",
        rangeField: ["creationTime", "creationTime"],
        edit: true
    },
    {
        enname: "billCode",
        zhname: "单据号",
        required: false,
        type: "FormControl",
        searchType:"like",
        edit: true
    },
    {
        enname: "organization",
        zhname: "所属组织",
        required: false,
        refname:"organization",
        realRef:true,
        param:{
            "AUTH_refdim": "organization", 
            "AUTH_refcod": "ExpenseSummary"
        },
        type: "RefComponent",
        edit: true
    },
    {
        enname:"state",
        zhname:"审批状态",
        required: false,
        code:"BILL_STATUS",
        type: "Select",
        edit: true
    },
]

export const headerButtonSets = [
    // {
    //     event: "ButtonAdd",
    //     zhname: "新增",
    //     color: 'primary',
    //     authcode: "9901-05-02-01",
    // }
    // {
    //     event: "ButtonEnable",
    //     zhname: "启用",
    //     authcode: "ActivityDesignstart",
    //     method: "post",
    //     batch:true,
    //     ContentType: 'application/x-www-form-urlencoded;charset=utf-8',
    //     url: 'occ-fee/fee/expense-summary/enable'
    // },
    // {
    //     event: "ButtonEnable",
    //     zhname: "停用",
    //     authcode: "ActivityDesignstop",
    //     method: "post",
    //     batch:true,
    //     ContentType: 'application/x-www-form-urlencoded;charset=utf-8',
    //     url: 'occ-fee/fee/expense-summary/disenable'
    // }
]

export const columnButtonSets = {
    "delete": {
        event: "ButtonDel",
        zhname: "删除",
        batch: true,
        method: "post",
        ContentType: 'application/x-www-form-urlencoded;charset=utf-8',
        url: 'occ-fee/fee/activity-design/deleteWithFriendly'
    },
    "edit": true,
    "detail": true
}

// export default {mainTableColumn,searchField,headerButtonSets,
//     columnButtonSets,childTableColumn,FormTableField,FormField}
export const SelectCode = ["QY132","ls002","ls001","sale","FA001","BILL_STATUS","BILL_TYPE_FEE","SALE_STATISTIC_BASIS","QRSP001"]
